<form id="formEdit" action="profession/save" class="form-horizontal" role="form" >
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">操作</h4>
            </div>
            <div class="modal-body">

            	<!-- 以下为要修改的的内容 -->

				<input type="hidden" name="id" data-th-value="${model.id}">
				
                <div class="form-group">
                	<label for="txt_year" class="col-sm-2 control-label">年级</label>
                	<div class="col-sm-9">
	                    <input type="text" name="year" data-th-value=${model.year} class="form-control" id="year" placeholder="年级">
                	</div>   
                </div>
                <div class="form-group">
                	<label for="txt_college" class="col-sm-2 control-label">学院</label>
                	<div class="col-sm-9">
                		<select id="college" name="college"  class="selectpicker form-control">
								<option th:text="${model.college}" th:value="${model.college}" style="display: none; "></option>
							</select>
	                   <!--  <input type="text" name="college" data-th-value=${model.college} class="form-control" id="college" placeholder="学院"> -->
                	</div>
                </div>
                <div class="form-group">
                	<label for="txt_profesion" class="col-sm-2 control-label">专业</label>
                	<div class="col-sm-9">
	                    <input type="text" name="profesion" data-th-value=${model.profesion} class="form-control" id="profesion" placeholder="专业">
                	</div>
                </div>
                
                 <div class="form-group">
                	<label for="txt_profesion" class="col-sm-2 control-label">代码</label>
                	<div class="col-sm-9">
	                    <input type="text" name="code" data-th-value=${model.code} class="form-control" id="code" placeholder="专业代码">
                	</div>
                </div>

                <!-- 以上为要修改的内容 -->

            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript" th:inline="javascript">

 	var options= {
			message: '验证不通过',
			feedbackIcons: {
                 valid: 'glyphicon glyphicon-ok',
                 invalid: 'glyphicon glyphicon-remove',
                 validating: 'glyphicon glyphicon-refresh'
             },
             fields: { 

            	year: {
    				validators: {
    					notEmpty: {
    						message: '年级不能为空！'
    					},
    					digits : {
    					    message : '请输入正确的年级！'
    					}
    				}
    			},
    			college: {
    				validators: {
    					notEmpty: {
    						message: '学院不能为空'
    					}
    				}
    			},
    			profesion: {
    				validators: {
    					notEmpty: {
    						message: '专业不能为空'
    					}
    				}
    			},
    			code:{
    				validators: {
    					regexp: {
    					    regexp: /^[a-zA-Z0-9_]+$/,
    					    message: '课程代码只能输入数字英文或者下划线！'
    					}
    				}
    			}
             	
             }
         };
        $('#formEdit').bootstrapValidator(options).on('success.form.bv', function(e) {
        	e.preventDefault();							   	//很重要没有它则会提交默认表单，不会做下面的ajax表单提交
            var fd = new FormData($("#formEdit")[0]); 
            var url=$('#formEdit').attr('action');
            $.ajax({  
              url: url,  
              type: "POST",  
              data: fd,
               processData: false,  // 不处理数据  
              contentType: false,   // 不设置内容类型 
              success:function(result){
            	  if(result.success){
	            	  $('#myModal').modal("hide");
            	  }else{
            		  bootbox.alert(result.msg);
            	  }
              },
              error:function(result){
            	  alert(result);
              }
            });  
    	});

$(function(){
	//初始化学院下拉框
	$("#college").selectpicker({
		title : '选择学院'
	});
	
	$.post('profession/foundCollegeInput',function(data){
		   for (var i = 0; i < data.length; i++) {  
	            $('#college').append("<option value=" + data[i].name + "> "+data[i].name +"</option>");  
	        }  
	        // 缺一不可  
	        $('#college').selectpicker('refresh');  
	});
});
</script>